//
//  CommentViewController.m
//  Inner  Voice
//
//  Created by 逗比小胖！ on 16/3/7.
//  Copyright © 2016年 徐海宇. All rights reserved.
//

#import "CommentViewController.h"
#import "Friend.h"

@interface CommentViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *textLabel;
@property (weak, nonatomic) IBOutlet UIImageView *picImage;
@property (weak, nonatomic) IBOutlet UITableView *commentTableView;
@property (weak, nonatomic) IBOutlet UITextField *commentText;

@property (nonatomic, strong) NSMutableArray *commentArray;

@property(nonatomic,strong)Friend *friend;
@end

@implementation CommentViewController

- (NSMutableArray *)commentArray {
    if (!_commentArray) {
        _commentArray = [NSMutableArray arrayWithArray:@[@"dfafdsa",@"aaaa",@"bbb",@"cccc",@"ddddd"]] ;
    }
    return _commentArray;
}

- (IBAction)senderBtnClick:(id)sender {
    if([self.commentText.text isEqualToString:@""]){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"内容不能为空" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }
    [self.commentArray addObject:self.commentText.text];
    
    self.commentText.text = @"";
    [self.commentTableView reloadData];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    if(self.commentFriendBlock){
     
        Friend *friend = [[Friend alloc]init];
       friend = self.commentFriendBlock();
        self.iconImage.image =[UIImage imageNamed:friend.icon];
        self.nameLabel.text = friend.name;
        self.textLabel.text = friend.text;
        
        self.picImage.image = [UIImage imageNamed:friend.picture];
        self.friend= friend;
        NSLog(@"%@",self.friend);
        }
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.commentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = self.commentArray[indexPath.row];
    return cell;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
